from sqlalchemy import Column, Integer, String, Boolean
from sqlalchemy.orm import relationship
from .base import Base, TimestampMixin
from .learning import user_knowledge_enrollments

class User(Base, TimestampMixin):
    __tablename__ = "users"

    id = Column(Integer, primary_key=True, index=True)
    email = Column(String, unique=True, index=True, nullable=False)
    phone = Column(String, unique=True, index=True)  # 手机号
    username = Column(String, unique=True, index=True, nullable=False)
    hashed_password = Column(String, nullable=False)
    is_active = Column(Boolean, default=True)
    is_superuser = Column(Boolean, default=False)

    # 学习相关字段
    grade_level = Column(String)  # 年级水平
    subjects = Column(String)  # 关注的学科，JSON字符串
    learning_style = Column(String)  # 学习风格偏好

    # 关联关系
    learning_plans = relationship("LearningPlan", back_populates="user")
    progress_records = relationship("Progress", back_populates="user")
    enrolled_knowledge = relationship("KnowledgeBase", secondary=user_knowledge_enrollments, back_populates="enrolled_users")